package com.itranswarp.weibo.api;

enum HttpMethod {
	GET,
	POST,
	UPLOAD,
}

class ApiInvocation {
	final HttpMethod httpMethod;
	final String url;
	final ApiParam[] params;

	public ApiInvocation(HttpMethod httpMethod, String url, ApiParam... params) {
		this.httpMethod = httpMethod;
		this.url = url;
		this.params = params;
	}
}

class ApiParam {

	final String name;
	final Class<?> type;
	final boolean optional;
	final Object value;

	ApiParam(String name, Class<?> type) {
		this.name = name;
		this.type = type;
		this.optional = false;
		this.value = null;
	}

	ApiParam(String name, Class<?> type, Object value) {
		this.name = name;
		this.type = type;
		this.optional = true;
		this.value = value;
	}

	void checkArg(Object o) {
		if ((o != null) && ! type.isInstance(o)) {
			String actualType = o==null ? "null" : o.getClass().getName();
			throw new WeiboException("Expected argument type '" + type.getSimpleName() + "' but actual is '" + actualType + "'");
		}
	}
}
